package com.mingqi.hw.test3140;

import java.util.*;

/**
 *
 */
public class ZT35 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] input = sc.nextLine().split(" ");
        String[] job = sc.nextLine().split(" ");
        int med = Integer.parseInt(input[0]);
        int[] arr = new int[job.length];
        for (int i = 0; i < job.length; i++) {
            arr[i] = Integer.parseInt(job[i]);
        }
        Arrays.sort(arr);
        List<Medic> list = new ArrayList<>();
        for (int i = 0; i < arr.length; i++) {
            if (list.size() <med){
                list.add(new Medic(arr[i],arr[i]));
            }else {
                //找到数组中 total最小的medic 加进去
                Collections.sort(list);
                Medic medic = list.get(0);
                medic.total += arr[i];
            }
        }
        Collections.sort(list);
        System.out.println(list.get(list.size()-1).total);
    }
    static class Medic implements Comparable{
        private int end;
        private int total;

        public Medic(int end, int total) {
            this.end = end;
            this.total = total;
        }

        @Override
        public int compareTo(Object obj) {
            Medic medic= (Medic)obj;
            return this.total - medic.total;
        }
    }
}
